package com.tmc.service.intcar;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.tmc.bean.common.CommonResult;
import com.tmc.bean.common.ContextInfo;
import com.tmc.bean.intcar.EthOrderFinishedReq;
import com.tmc.constant.IntcarOrderConstant;
import com.tmc.entity.intcar.IntcarOrder;

/**
 * @author zhang
 * @date 2017年12月29日 下午4:26:28 
 */
@Service
public class IntcarOrderFinishedServiceImpl {
	
	private Log log = LogFactory.getLog(IntcarOrderFinishedServiceImpl.class);
	
	@Autowired
	private IntcarOrderServiceImpl orderService;
	
	public CommonResult orderFinished(ContextInfo context, EthOrderFinishedReq request){
		IntcarOrder dbOrder = orderService.getById(context, request.getOrderID());
		if(dbOrder == null){
			return CommonResult.makeFail("ID为"+request.getOrderID()+"的订单不存在！");
		}
		if(!dbOrder.getVendorOrderID().equals(request.getVendorOrderID())){
			return CommonResult.makeFail("供应商ID错误！");
		}
		//VendorService service = ServiceCenter.getService(dbOrder.getVendor());
		try {
			dbOrder.setOrderStatus(IntcarOrderConstant.ORDER_STATUS_FINISHED);
			CommonResult result = orderService.updateOrderStatus(context, dbOrder);
			return result;
		} catch (Exception e) {
			log.error("订单完成出错！", e);
		}
		return CommonResult.makeFail("订单完成出错！");
	}
}
